#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    ui->listWidget->addItem("c++");
    ui->listWidget->addItem("java");
    ui->listWidget->addItem("python");


}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_add_clicked()
{
    QString str = ui->lineEdit->text();
    if(str.isEmpty()) return;
    ui->listWidget->addItem(str);
    ui->lineEdit->setText("");
}

void Widget::on_pushButton_del_clicked()
{
    int row = ui->listWidget->currentRow();
    if(row<0) return;
    ui->listWidget->takeItem(row);
}

void Widget::on_listWidget_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous)
{
    if(current!=nullptr)
        ui->label_3->setText(current->text());

    if(previous!=nullptr)
        ui->label_4->setText(previous->text());
}
